import { InitializationService } from './../index';
import { PrividerService } from './../prividerService';
import { GrowlMessageType } from './../../../components/messageBox/growMeaageType';
import { MessageBoxService } from './../../../components/messageBox/messageBoxService';
import { Terminal } from './../../../models/terminal';
import { devciesService } from './../../../services/device';
import { NavigateManage } from './../../../common/navigateManage';
import { LocalstorageDataManage } from './../../../common/localstoreage/localstoreageDataManage';
import { businsessHttpServer } from './../../../common/http/http-server';
import { Component, OnInit } from '@angular/core';
@Component({
    selector: 'delivery-scheme',
    templateUrl: './deliveryScheme.component.html',
    styleUrls: ['./deliveryScheme.component.scss']
})

export class DeliverySchemeComponent implements OnInit {
    private kdsList;
    private selectedKdsItems = [];
    private terminal: Terminal = <Terminal>{
        id: "ddddddds",
        name: "D-1"
    };
    checkedOptions = []
    kdsIds;
    async  ngOnInit() {
        const data = await devciesService.getKDSDevice();
        this.kdsList = data;
        this.kdsIds = this.kdsList.map(x => {
            return { id: x.id, label: x.name }
        })
        console.log(this.kdsIds)
    }

    onChange(checkedOptions) {
        this.selectedKdsItems = this.kdsList.filter(kds => checkedOptions.indexOf(kds.id) > -1);
    }

    /**
     * 开始使用
     */
    beginUse() {
        if (!this.terminal.name) {
            MessageBoxService.current.Growl(GrowlMessageType.Error,"请设置终端名称");
            return false;
        }
        if (!this.selectedKdsItems || !this.selectedKdsItems.length) {
            MessageBoxService.current.Growl(GrowlMessageType.Error,"请选择出品台");
            return false;
        }
        LocalstorageDataManage.current.setTerminal(this.terminal);
        LocalstorageDataManage.current.setValidKDSs(this.selectedKdsItems);
        location.reload();
    }
    onBack() {
        PrividerService.current.navigate(InitializationService.current.getPathByComponentName("remoteLogin"))
    }
}